package com.example.calculatorApp.controller;

import com.example.calculatorApp.common.Result;
import com.example.calculatorApp.controller.request.resouceRequest;
import com.example.calculatorApp.entity.Resouce;
import com.example.calculatorApp.service.IResouceService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@ResponseBody
@RequestMapping("/resouce")
public class resouceController {

    @Autowired
    IResouceService IResouceService;

    @GetMapping("/list")
    public Object getList(resouceRequest resouceRequest) {
        return IResouceService.getList(resouceRequest);
    }

    @GetMapping("/admin/list")
    public Result getResouceList(resouceRequest resouceRequest) {
        return Result.success(new PageInfo<>(IResouceService.getList(resouceRequest)));
    }

    @PostMapping("/admin/save")
    public Result save(@RequestBody Resouce resouce){
        IResouceService.save(resouce);
        return Result.success("success");
    }

    @PostMapping("/admin/deleteById")
    public Result deleteById(@RequestBody Resouce resouce){
        IResouceService.deleteById(resouce.getId());
        return Result.success("success");
    }

    @PostMapping("/admin/updateById")
    public Result updateById(@RequestBody Resouce resouce){
        IResouceService.updateById(resouce);
        return Result.success("success");
    }
}
